package com.generic.mybatis.dal.interceptor.automap.builder;

import com.generic.mybatis.dal.interceptor.automap.SqlBuilder;
import com.generic.mybatis.dal.interceptor.automap.TableMapper;
import com.generic.mybatis.dal.interceptor.automap.TableMapperHolder;
import org.apache.ibatis.jdbc.SQL;
import org.apache.ibatis.mapping.MappedStatement;

import static com.generic.mybatis.dal.interceptor.automap.builder.SqlBuilderUtil.*;

/**
 * 分页查询
 *
 * @author wuaj
 */
public class FindByPageBuilder implements SqlBuilder {

    @Override
    public String buildSql(MappedStatement mappedStatement, Class dtoClass, Object parameterObject) {
        TableMapper tableMapper = TableMapperHolder.getTableMapper(dtoClass);
        SQL sql = buildSelectStatement(tableMapper);
        buildCritialStatement(tableMapper, sql, parameterObject, "param2");
        replaceResultMap(mappedStatement, tableMapper.getResultMap());
        return buildPagableStatement(tableMapper, sql, parameterObject, "param1");
    }

}
